<?php
/**
 * Created by PhpStorm.
 * User: ADMIN
 * Date: 2021/6/27
 * Time: 7:07
 */
namespace app\adminapi\validate;

class VariableAdd extends Base
{
    protected $rule = [
        'name' => 'require|nameUnique',
        'value' => 'require',
        'relation_key' => 'require',
    ];

    protected $message = [
        'name.nameUnique' => '变量名唯一',
    ];

    /**
     * 变量名唯一
     * @param $value
     * @return bool
     * @throws \think\Exception
     */
    protected function nameUnique($value)
    {
        if(db('variable')->where("name='{$value}'")->count()) return false;
        return true;
    }

}